var t = null, a = null, e = null, n = null;

Page({
    data: {
        loadingImg: !0,
        card_id: "",
        cardData: {},
        drawing: [],
        savebtnText: "保存名片码",
        canvasWidth: "",
        canvasHeight: "",
        showBtn: !1,
        ithumb: ""
    },
    onLoad: function(i) {
        var s = this;
        this.setData({
            card_id: i.card_id
        }), wx.getSystemInfo({
            success: function(i) {
                e = i.windowWidth / 375, n = i.windowWidth, t = 343 * e, a = 450 * e, s.setData({
                    canvasWidth: t,
                    canvasHeight: a
                });
            }
        }), wx.getStorage({
            key: "info",
            success: function(t) {
                var a = t.data.card_name.split("名");
                s.setData({
                    card_name: a[0]
                }), wx.getStorage({
                    key: "iconFrom",
                    success: function(t) {
                        s.setData({
                            min_code: t.data.min_code
                        }), s.getAvaterInfo();
                    }
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {},
    getAvaterInfo: function() {
        var e = wx.createCanvasContext("myCanvas");
        e.fillStyle = "#FFFFFF", e.fillRect((n - t) / 2, 20, t, a), e.setTextAlign("center"), 
        e.setFillStyle("#333"), e.setFontSize(15), e.fillText(this.data.card_name + "专属名片码", t / 2 + 10, 80), 
        e.drawImage(this.data.min_code, t / 2 - 80, 120, 180, 180), e.setTextAlign("center"), 
        e.setFillStyle("#333"), e.setFontSize(14), e.fillText("此名片码可印刷在", t / 2 + 10, 360), 
        e.setTextAlign("center"), e.setFillStyle("#50a6f9"), e.setFontSize(14), e.fillText("纸质名片、宣传单、海报、易拉宝等宣传册上", t / 2 + 20, 380), 
        e.setTextAlign("center"), e.setFillStyle("#8c8c8c"), e.setFontSize(13), e.fillText("扫一扫名片码即可查看", t / 2 + 10, 400), 
        e.draw(!0, this.toimage());
    },
    toimage: function() {
        var t = this;
        wx.hideLoading(), this.setData({
            showBtn: !0
        });
        var a = this;
        setTimeout(function() {
            wx.canvasToTempFilePath({
                x: 0,
                y: 0,
                height: t.data.canvasHeight,
                destWidth: t.data.canvasWidth,
                destHeight: t.data.canvasHeight,
                canvasId: "myCanvas",
                success: function(t) {
                    var e = t.tempFilePath;
                    a.setData({
                        ithumb: e
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }, 1e3);
    },
    createdImage: function(t) {
        console.log(t, "65566565454");
    },
    previewImage: function(t) {
        wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            height: this.data.canvasHeight,
            destWidth: 4 * this.data.canvasWidth,
            destHeight: 4 * this.data.canvasHeight,
            canvasId: "myCanvas",
            success: function(t) {
                var a = t.tempFilePath;
                console.log(a), wx.previewImage({
                    current: a,
                    urls: [ a ]
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    saveShareImg: function() {
        wx.showLoading({
            title: "保存中"
        }), wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            height: this.data.canvasHeight,
            destWidth: 4 * this.data.canvasWidth,
            destHeight: 4 * this.data.canvasHeight,
            canvasId: "myCanvas",
            success: function(t) {
                console.log(t), wx.saveImageToPhotosAlbum({
                    filePath: t.tempFilePath,
                    success: function(t) {
                        wx.showToast({
                            title: "图片保存成功",
                            icon: "success",
                            duration: 2e3
                        });
                    }
                });
            },
            fail: function(t) {
                wx.hideLoading();
            }
        });
    }
});